import React, { Component } from 'react';
import styles from './index.less';
import { history, formatMessage, useIntl, getDvaApp } from 'umi';
// import { Button } from 'antd';
import { getUrlParams } from '@/utils/urlUtil';

// ue4使用
import benchu, { ue4 } from 'benchu-ui';
import Button from 'benchu-ui/es/components/Button';
const { getUe4 } = ue4;
const { getUe4ToWebKyes, getWebToUe4Kyes, ep, webToUe4 } = getUe4();

//ue4 Event kye
const { ue4MsgFunction1 } = getUe4ToWebKyes;
const { setTime } = getWebToUe4Kyes;

export default class extends React.Component {
  // 初始化执行
  componentDidMount = () => {
    // 获取ue4带过来的参数
    console.log(getUrlParams());

    // 接管ue4回调函数
    ep.on(ue4MsgFunction1, this[ue4MsgFunction1]);

    console.log('----------------------------------------');
    console.log(benchu);
    console.log(ue4);
  };

  //销毁前执行
  componentWillUnmount = () => {
    ep.removeListener(ue4MsgFunction1);
  };

  // ue4的回调函数
  [ue4MsgFunction1] = data => {
    console.log(data);
    console.log('进来了啊');
  };

  render() {
    return (
      <div>
        <Button onClick={() => webToUe4(setTime, { name: '小明', age: 18 })}>
          按钮
        </Button>
      </div>
    );
  }
}
